package com.ruoyi.bigScreen;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.TreeSelect;
import com.ruoyi.common.core.domain.zzw.LongListDto;
import com.ruoyi.common.core.domain.zzw.TRegionInfo;
import com.ruoyi.common.core.domain.zzw.TTagManage;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.ITTagManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 标签Controller
 *
 * @author xbx
 * @date 2023-10-20
 */

@Api(tags = "标签管理")
@RestController
@RequestMapping("/screen/tag")
public class ScreenTagManageController extends BaseController {
    @Autowired
    private ITTagManageService tTagManageService;

    @ApiOperation("获取标签下拉树列表")
    @GetMapping("/treeSelect")
    public AjaxResult treeSelect(String type) {

        List<TreeSelect> selects = new ArrayList<>();
        List<TTagManage> regions = tTagManageService.listByType(type);
        if (CollectionUtils.isEmpty(regions)) {
            return AjaxResult.success(selects);
        }
        for (TTagManage tag : regions) {
            TreeSelect select = new TreeSelect();
            select.setId(tag.getcTagId());
            select.setLabel(tag.getcTagName());
            select.setParentId(tag.getcFatherTagId());
            selects.add(select);
        }
        List<TreeSelect> selectList = TreeSelect.buildTree(selects);
        return success(selectList);
    }
}
